const app = getApp()
const request = require('../../../utils/request.js')
const util = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    refundGoodInfo: {},
    array: ['商品成分描述不符', '商品损坏/少件/变形等', '尺寸/规格不符', '颜色/款式/包装与商品描述不符', '其它原因'],
    hasPicked: false,
    imgs: [
      
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    var that = this;
    console.log(app.globalData.orderItemsArr)
    var orderId = options.orderId;
    var goodId = options.goodId;
    var standard = options.standard;
    console.log(options.orderId);
    var url = request.URL + '/order/byOrderId';
    var refundGoodInfo = {};
    request.request({
      url: url,
      data: {
        orderId: orderId
      },
      success: function(res) {
        console.log(res);
        var goodArr = res.data.orderVO.goodVOS;
        for (var i = 0; i < goodArr.length; i++) {
          var selectedgoodId = goodArr[i].goodId;
          var selectedStandard = goodArr[i].standard;
          if (selectedgoodId == goodId && selectedStandard == standard) {
            refundGoodInfo = goodArr[i];
          }
        }
        var goodImgArray = util.string2Array(refundGoodInfo.goodImgArray);
        refundGoodInfo.goodImgArray = goodImgArray
        console.log(refundGoodInfo)
        that.setData({
          refundGoodInfo: refundGoodInfo
        })
      },
      fail: function() {
        request.showFailInfo()
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  /**选择退款原因 */
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value,
      hasPicked: true
    })
  },
  /**上传图片 */
  uploadImg: function(e) {
    var that = this;
    wx.chooseImage({
      count: 3,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function(res) {
        console.log(res);
        var imgsArr = res.tempFilePaths;
        that.setData({
          imgs: imgsArr
        })
      },
    })
  },
  /**预览图片 */
  previewImg:function (e) {
    var that = this;
    var urls = that.data.imgs;
    var url = e.currentTarget.dataset.url;
    wx.previewImage({
      urls: urls,
      current: url,
    })
  }
})